#!/bin/bash

systemctl stop firewalld.service

systemctl disable firewalld.service

wget https://www.percona.com/downloads/pmm/1.9.0/docker/pmm-server-1.9.0.docker

yum install docker -y

systemctl enable docker
systemctl start docker

docker image load -i pmm-server-1.9.0.docker

docker create -v /opt/prometheus/data -v /opt/consul-data -v /var/lib/mysql -v /var/lib/grafana --name pmm-data percona/pmm-server:1.9.0 /bin/true

docker run -d  -p 80:80 --volumes-from pmm-data --name pmm-local --restart always percona/pmm-server:1.9.0

pmm-admin config --server 127.0.0.1

mysql -uroot -p -e"grant all privileges on *.* to 'pmm'@'localhost' identified by '123456' with grant option"

# 如果执行pmm-admin check-network发现慢查询分析服务提示
# We have found system services disconnected from PMM server.
# Usually, this happens when data container is wiped before all monitoring services are removed or client is uninstalled.
# 将mysql的原有慢查询日志和错误日志清空即可。

#cat /dev/null > /datadir/slow.log
#cat /dev/null > /datadir/error.log

pmm-admin add mysql --user pmm --password 123456 --host localhost

pmm-admin check-network